﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using ElegantRoute.Routing;
namespace ShopWeb
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //注册
            routes.MapElegantRoute("Register", "register", new { controller = "Member", action = "Register" });
            //登录
            routes.MapElegantRoute("Login", "login", new { controller = "Member", action = "Login" });
            //女用
            routes.MapElegantRoute("Woman", "woman", new { controller = "Category", action = "Detail", Cid = 2 });
            //男用
            routes.MapElegantRoute("man", "man", new { controller = "Category", action = "Detail", Cid = 3 });
            //双人情趣
            routes.MapElegantRoute("couple", "couple", new { controller = "Category", action = "Detail", Cid = 4 });
            //情趣内衣
            routes.MapElegantRoute("neiyi", "neiyi", new { controller = "Category", action = "Detail", Cid = 5 });
            // 安全套
            routes.MapElegantRoute("condom", "condom", new { controller = "Category", action = "Detail", Cid = 7 });
            //商品分类
            routes.MapElegantRoute("Category", "category/s/{cid}/{page}", new { controller = "Category", action = "Detail", Cid = UrlParameter.Optional, page = UrlParameter.Optional });
            //商品详情
            routes.MapElegantRoute("Product", "product/s/{pid}", new { controller = "Product", action = "Detail", pid = UrlParameter.Optional });

            //文章详情
            routes.MapElegantRoute("Aticle", "article/s/{aid}", new { controller = "Article", action = "Detail", aid = UrlParameter.Optional });

            //routes.MapRoute(
            routes.MapElegantRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}